package com.yc.bdw.Activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.ListView;

import com.yc.bdw.Adapter.PaymentListAdapter;
import com.yc.bdw.R;
import com.yc.bdw.Utils.Constant;
import com.yc.bdw.model.SituationItem;
import com.yc.bdw.Widget.CustomToast;

import org.kymjs.kjframe.KJActivity;
import org.kymjs.kjframe.ui.BindView;

import java.util.ArrayList;
import java.util.List;

public class PaymentActivity extends KJActivity {
    @BindView(id = R.id.payment_back, click = true)
    private ImageView backBtn;
    @BindView(id = R.id.payment_confirm, click = true)
    private ImageView confirmBtn;
    @BindView(id = R.id.payment_list, click = true)
    private ListView paymentList;

    private List<SituationItem> payments = new ArrayList<SituationItem>();
    private PaymentListAdapter adapter;

    @Override
    public void setRootView() {
        setContentView(R.layout.activity_payment);
    }

    @Override
    public void initData() {
        super.initData();

        init();

        adapter = new PaymentListAdapter(aty);
        adapter.setList(payments);
        adapter.init();
    }

    private void init() {
        SituationItem item = new SituationItem();
        item.setName("微信支付");
        payments.add(item);

        SituationItem item1 = new SituationItem();
        item1.setName("支付宝支付");
        payments.add(item1);

        SituationItem item2 = new SituationItem();
        item2.setName("银联支付");
        payments.add(item2);

        SituationItem item3 = new SituationItem();
        item3.setName("VIP卡支付");
        payments.add(item3);
    }

    @Override
    public void initWidget() {
        super.initWidget();

        paymentList = (ListView) findViewById(R.id.payment_list);
        paymentList.setAdapter(adapter);
    }

    @Override
    public void widgetClick(View v) {
        super.widgetClick(v);
        switch (v.getId()) {
            case R.id.payment_back:
                finish();
                break;
            case R.id.payment_confirm:
                int position = adapter.getWhich();
                if ( position == -1 ) {
                    CustomToast.showToast(aty,R.string.noPayment, Constant.toastDuring);
                } else {
                    Intent intent = new Intent();
                    Bundle bundle = new Bundle();
                    bundle.putString("payment",payments.get(position).getName());
                    intent.putExtras(bundle);
                    setResult(Constant.payment_ok,intent);
                    finish();
                }
                break;
        }
    }
}
